﻿using System.Xml;

namespace RDPManager
{
    class ConfigLoader
    {
        public static RdpConfig Main_config;

        public static void Load()
        {
            Main_config = new RdpConfig("main");
            XmlDocument doc = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;
            XmlReader reader = XmlReader.Create(@"data\rdp_config.xml", settings);
            doc.Load(reader);
            XmlNode root = doc.SelectSingleNode("all");
            XmlNodeList xnl = root.ChildNodes;
            foreach (XmlNode child in xnl)
            {
                XmlElement elem = (XmlElement) child;
                if (elem.Name.Equals("dir"))
                {
                    string name = elem.GetAttribute("name");
                    RdpConfig rdpConfig = new RdpConfig(name);
                    rdpConfig.parse(elem);
                    Main_config.Dirs.Add(rdpConfig);
                }
                else
                {
                    SingleConfig singleConfig = new SingleConfig();
                    singleConfig.parse(elem);
                    Main_config.Singles.Add(singleConfig);
                }
            }
            reader.Close();
        }
    }
}
